//
//  MessageHandCell.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/8/21.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class MessageHandCell: TableRowView {
    static let identifier = NSUserInterfaceItemIdentifier.init("MessageHandCell")
    var clickBlock:BtnTapBlock?
    
    convenience init(identifier:NSUserInterfaceItemIdentifier) {
        self.init()
        self.setupUI()
    }
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    convenience init(identifier:NSUserInterfaceItemIdentifier,clickBlock:BtnTapBlock?) {
        self.init()
        self.identifier = identifier
        self.clickBlock = clickBlock
        self.setupUI()
    }
    
    
    
    func setupUI()  {
        //self.focusRingType = .none

        self.addSubview(stitle)
        stitle.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-60)
            make.height.equalTo(20)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.height.equalTo(0.6)
            make.width.equalToSuperview().offset(-30)
            make.bottom.equalToSuperview().offset(-1)
            make.centerX.equalToSuperview()
        }
        self.addSubview(downBtn)
        downBtn.snp.makeConstraints { (make) in
            make.width.equalTo(40)
            make.height.equalTo(22)
            make.centerY.equalToSuperview()
            make.right.equalTo(-15)
        }
    }
    
    
    lazy var lineView: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = color_gray(240).withAlphaComponent(1).cgColor
        return view
    }()
    
    lazy var stitle: NSLabel = {
        let lab = NSLabel.label(title: "标题", textColor: color_gray(40), font: NSFont.systemFont(ofSize: 12))
        lab.cell?.lineBreakMode = .byCharWrapping
        lab.cell?.truncatesLastVisibleLine = true
        return lab
    }()
    
    lazy var downBtn: ZHButton = {
        let btn = ZHButton.init()
        btn.zh_title = "放手"
        btn.zh_color = color_main108
        btn.hasBorder = true
        btn.zh_borderWidth = 1
        btn.zh_cornerRadius = 2
        btn.zh_borderColor = color_main140.withAlphaComponent(0.2)
        btn.hoverColor = NSColor.white
        btn.backgroundHoverColor = color_main108
        btn.target = self
        btn.action = #selector(downBtnAction(senber:))
        return btn
    }()
    
    @objc func downBtnAction(senber:ZHButton) {
        if self.clickBlock != nil {
            self.clickBlock!(senber)
        }
    }
}
